package com.xgst.baselib

import android.app.Application
import android.content.Context
import android.view.Gravity
import com.blankj.utilcode.util.CrashUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.PathUtils
import com.blankj.utilcode.util.ProcessUtils
import com.blankj.utilcode.util.ToastUtils
import com.xgst.lib.R

open abstract class BaseApplication : Application() {

    companion object {
        private lateinit var instance: Context
        fun sContext() = instance
    }

    override fun onCreate() {
        super.onCreate()
        if (ProcessUtils.isMainProcess()) {
            instance = this

            ToastUtils.getDefaultMaker()
                .setGravity(Gravity.CENTER, 0, 0)
                .setBgColor(getColor(R.color.black333))
                .setTextColor(getColor(R.color.white))

            LogUtils.getConfig()
                .setLog2FileSwitch(true)
                .setGlobalTag("ttt")
                .setDir(PathUtils.getRootPath())

            CrashUtils.init()

            init()
        }
    }

    abstract fun init()
}